﻿using Atlanchim.Crm.Mui.Helpers;
using FirstFloor.ModernUI.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Atlanchim.Crm.Mui.Pages.Adresses
{
    /// <summary>
    /// Interaction logic for PageListAdresses.xaml
    /// </summary>
    public partial class PageListAdresses : UserControl, IContent, IPageList
    {
        public PageListAdressesModel Model { get; set; }

        public PageListAdresses()
        {
            InitializeComponent();
            InitializeModel();
            InitializeCommands();
        }

        public void InitializeModel()
        {
            this.Model = new PageListAdressesModel();
            this.Model.Load();
            this.DataContext = this.Model;
        }

        public void InitializeCommands()
        {
            this.CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, TopNavigationHelper.OnGoToPage, TopNavigationHelper.OnCanGoToPage));
        }

        public void OnFragmentNavigation(FirstFloor.ModernUI.Windows.Navigation.FragmentNavigationEventArgs e)
        {
            this.Model.Fragment = e.Fragment;
            if (!string.IsNullOrEmpty(this.Model.Fragment))
            {
                this.Model.Load();
            }
        }

        public void OnNavigatedFrom(FirstFloor.ModernUI.Windows.Navigation.NavigationEventArgs e)
        {
        }

        public void OnNavigatedTo(FirstFloor.ModernUI.Windows.Navigation.NavigationEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.Model.Fragment))
            {
                this.Model.Load();
            }
        }

        public void OnNavigatingFrom(FirstFloor.ModernUI.Windows.Navigation.NavigatingCancelEventArgs e)
        {
        }
    }
}
